//
// Created by jsjxsy on 2022/8/29.
//
//指定类型
#include <cstring>
#include <iostream>
using namespace std;
template<unsigned N, unsigned M>
int compare(const char (&p1)[N], const char (&p2)[M]) {
  return strcmp(p1, p2);
}

template<class N, class M>
inline void f1(const N arg1, const M arg2) {
  cout << "f1" << endl;
}

//模版函数定义的模版只能作用在当前函数
//inline void f2(const N arg1, const M arg2) {
//  cout << "f2" << endl;
//}

template<typename T>
int compare1(const T &t1, const T &t2) {
  if (t1 < t2) { return -1; }
  if (t2 < t1) { return 1; }
  return 0;
}

template<typename T=int>
int compare2(const T &t1, const T &t2) {
  if (less<T>()(t1, t2)) { return -1; }
  if (less<T>()(t2, t1)) { return 1; }
  return 0;
}

template<>
int compare2(const int &t1, const int &t2) {
  if (less<int>()(t1, t2)) { return -1; }
  if (less<int>()(t2, t1)) { return 1; }
  return 0;
}

template<class T>
void simple(T t) {
  cout << t << '\n';
}
//返回值
template<class T>
T simple2(string args1) {
  cout << args1 << '\n';
  return (T) args1;
}

int main() {
  //int compare(const char (&p1)[6], const char (&p2)[5])
  int result = compare("hello", "word");
  cout << "result=" << result << endl;
  int result2 = compare1(1, 2);
  cout << "result2=" << result2 << endl;
  int result3 = compare1(5, 4);
  cout << "result3=" << result3 << endl;

  compare2(1.1f, 3.3f);
  compare2(1.11, 3.33);
  int a = 3;
  int b = 4;
  compare2(a, b);
  compare2(1, 3);


  simple("two");
  simple2<string>("three");
  return 0;
}

